package com.itcam.list_.generics_;

import java.util.ArrayList;

/**
 * Author:Cammy.Wu
 * Date:2024-06-02
 * Description:
 */

public class GenerticsDemo05 {
    /**
     * 泛型通配符
     * 1.？ : 任意类型
     * 2.? extends E : 可以传入的是E，或者是E的子类
     * 3.？ super E : 可以传入的是E，或者是E的父类
     */
    public static void main(String[] args) {
        ArrayList<Coder> coders = new ArrayList<>();
        coders.add(new Coder());

        ArrayList<Manager> managers = new ArrayList<>();
        managers.add(new Manager());

        methodExtend(coders);
        methodExtend(managers);

        methodSuper(managers);

    }

    public static void methodExtend(ArrayList<? extends Employee> list) {
        for (Object o : list) {
            Employee e = (Employee) o;
            e.work();
        }
    }

    public static void methodSuper(ArrayList<? super Manager> list) {
        for (Object o : list) {
            Manager e = (Manager) o;
            e.work();
        }
    }

}

abstract class Employee {
    private String name;
    private double salary;

    public Employee() {
    }

    public Employee(String name, double salary) {
        this.name = name;
        this.salary = salary;
    }

    public abstract void work();
}

class Coder extends Employee {

    @Override
    public void work() {
        System.out.println("程序员写代码。。。");
    }
}

class Manager extends Employee {

    @Override
    public void work() {
        System.out.println("项目经理分配任务。。。");
    }
}